package cn.demo.pm.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.demo.common.annotation.Log;
import cn.demo.common.core.controller.BaseController;
import cn.demo.common.core.domain.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.demo.common.enums.BusinessType;
import cn.demo.pm.domain.PmIntegralBill;
import cn.demo.pm.service.IPmIntegralBillService;
import cn.demo.common.utils.poi.ExcelUtil;
import cn.demo.common.core.page.PageR;
import cn.demo.common.core.page.PageQuery;
import com.mybatisflex.core.paginate.Page;


/**
 * 积分账单Controller
 *
 * @author xtjun
 * @date 2024-06-04
 */
@Tag(name = "积分账单")
@RestController
@RequestMapping("/pm/pmIntegralBill")
public class PmIntegralBillController extends BaseController {
    @Resource
    private IPmIntegralBillService pmIntegralBillService;

    @Operation(summary = "查询积分账单列表")
    @PreAuthorize("@ss.hasPermi('pm:pmIntegralBill:list')")
    @GetMapping("/list")
    public PageR<PmIntegralBill> list(PmIntegralBill pmIntegralBill, PageQuery pageQuery) {
        Page<PmIntegralBill> page = pmIntegralBillService.selectPmIntegralBillPage(pmIntegralBill, pageQuery);
        return PageR.ok(page);
    }

    @Operation(summary = "导出积分账单列表")
    @PreAuthorize("@ss.hasPermi('pm:pmIntegralBill:export')")
    @Log(title = "积分账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmIntegralBill pmIntegralBill) {
        List<PmIntegralBill> list = pmIntegralBillService.selectPmIntegralBillList(pmIntegralBill);
        ExcelUtil<PmIntegralBill> util = new ExcelUtil<PmIntegralBill>(PmIntegralBill.class);
        util.exportExcel(response, list, "积分账单数据");
    }

    @Operation(summary = "获取积分账单详细信息")
    @PreAuthorize("@ss.hasPermi('pm:pmIntegralBill:query')")
    @GetMapping(value = "/{id}")
    public R<PmIntegralBill> getInfo(@PathVariable("id") String id) {
        return R.ok(pmIntegralBillService.selectPmIntegralBillById(id));
    }

    @Operation(summary = "新增积分账单")
    @PreAuthorize("@ss.hasPermi('pm:pmIntegralBill:add')")
    @Log(title = "积分账单", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody PmIntegralBill pmIntegralBill) {
        return toAjax(pmIntegralBillService.insertPmIntegralBill(pmIntegralBill));
    }

    @Operation(summary = "修改积分账单")
    @PreAuthorize("@ss.hasPermi('pm:pmIntegralBill:edit')")
    @Log(title = "积分账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody PmIntegralBill pmIntegralBill) {
        return toAjax(pmIntegralBillService.updatePmIntegralBill(pmIntegralBill));
    }

    @Operation(summary = "删除积分账单")
    @PreAuthorize("@ss.hasPermi('pm:pmIntegralBill:remove')")
    @Log(title = "积分账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable List<String> ids) {
        return toAjax(pmIntegralBillService.deletePmIntegralBillByIds(ids));
    }
}
